<template>
  <div>
    <form action="/">
      <van-search
        v-model="keywords"
        placeholder="请输入搜索关键词"
        show-action
        @cancel="$router.back()"
      />
    </form>
    <van-cell
      :title="item.communityName"
      v-for="(item, index) in communityList"
      :key="index"
      @click="toRent(item)"
    ></van-cell>
  </div>
</template>
<script>
import { getCommunityApi } from "@/api";
export default {
  name: "RentSearch",
  data() {
    return {
      keywords: "",
      id: this.$store.state.parmas.cityId,
      communityList: [],
    };
  },
  components: {},
  computed: {},
  methods: {
    toRent(item) {
      this.$router.push({
        name: "Rent",
        params: item,
      });
    },
  },
  watch: {
    async keywords() {
      if (!this.keywords) {
        this.communityList = [];
        return;
      }
      const { data } = await getCommunityApi({
        name: this.keywords,
        id: this.id,
      });
      console.log(data);
      this.communityList = data.body;
    },
  },
};
</script>
<style lang="" scoped></style>
